/*======================================================================
== Copyright : BlueCurve (c)
== Licence   : Gnu/GPL v2.x
== Author    : Teddy Albina
== Email     : bluecurveteam@gmail.com
== Web site  : http://www.codeplex.com/BlueCurve
========================================================================*/
// Il s'agit du fichier DLL principal.
#include "stdafx.h"
#include "DbXml.hpp"
using namespace DbXml;
using namespace std;
#include "NativeMethods.h"
#include "Berkeleydbxml.h"
#include <vcclr.h>

using namespace Berkeleydbxml;


BerkeleydbxmlWrapper::BerkeleydbxmlWrapper(System::String ^dbname,  System::String ^containername, System::String ^envHome, System::Boolean debug, System::UInt32 gbytes_cache, System::UInt32 bytes_cache, System::Int32 number_of_cache)
{
	std::string _dbname = "";
	std::string _containername = "";
	std::string _envHome = "";
    MarshalString(dbname, _dbname);
	MarshalString(containername, _containername);
	MarshalString(envHome, _envHome);

	this->dbxml = new NativeMethods(_dbname, _containername, _envHome, debug, gbytes_cache, bytes_cache, number_of_cache);
}

System::Boolean BerkeleydbxmlWrapper::AddBranch(System::String ^baselink)
{
	Console::WriteLine(baselink);
    std::string _baselink = "";
	//MarshalString(baselink, _baselink);
	Console::WriteLine("--------------------------");
	char* chars = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(baselink).ToPointer();
	std::cout << "fuck " << chars << std::endl;
	System::Runtime::InteropServices::Marshal::FreeHGlobal(IntPtr(chars));
	Console::WriteLine("--------------------------");


	return this->dbxml->AddBranch("RRRRRRRRRRRRRRRRRRRRRRRR");
}

System::Boolean BerkeleydbxmlWrapper::AddNodeToBranch(System::String ^baselink, System::String ^link, System::String ^typeoffnode)
{
	std::string _baselink = "";
	std::string _link = "";
	std::string _typeoffnode = "";
    MarshalString(baselink, _baselink);
	MarshalString(link, _link);
	MarshalString(typeoffnode, _typeoffnode);

	return this->dbxml->AddNodeToBranch(_baselink, _link, _typeoffnode);
}

System::Boolean BerkeleydbxmlWrapper::CheckBranchExist(System::String ^baselink)
{
	std::string _baselink = "";
	MarshalString(baselink, _baselink);

	return this->dbxml->CheckBranchExist(_baselink);
}

BerkeleydbxmlWrapper::~BerkeleydbxmlWrapper()
{
	if(this->dbxml != NULL)
		delete this->dbxml;
}
